<%@page import="helpers.UrlHelper"%>
<%@page import="models.LinkModel"%>
<%@page import="models.CategoryModel"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.TreeMap"%>
<%
TreeMap check = (TreeMap) request.getAttribute("check");
ArrayList<CategoryModel> categories = (ArrayList<CategoryModel>) request.getAttribute("categories");
String success = (String) request.getAttribute("success");
CategoryModel category = (CategoryModel) request.getAttribute("category");
boolean hasChildren = (Boolean) request.getAttribute("hasChildren");
String form = (String) request.getAttribute("form");
%>

<jsp:include page="/admin/layouts/header.jsp">
    <jsp:param name="language" value="1" />
</jsp:include>
<script type="text/javascript" src="/admin/js/form_category.js"></script>
<script type="text/javascript">
var server = "<%=UrlHelper.getServerUrl(request)%>";
</script>
	<% if (success != null) {%>
	<div class="success block" ><%=success %></div>
	<% } %>
	<div class="block">
		<form id="edit_category_form" action="" method="post">
			<div id="add_items">
				<table class="formPage">
					<thead>
						<tr>
							<th colspan="2">
								Category Form
							</th>
						</tr>
					</thead>
					<tbody>
						<tr>
							<td class="label"><label for="c_name">Name:</label></td>
							<td class="smallDesc type">
								<% if (check.get("name") != null) { %>
									<span class="error"><%=check.get("name") %></span>
								<% } %>
								<input id="c_name" class="text" type="text" name="name" value="<%=category.getName()%>" maxlength="100">
							</td>
						</tr>
						<tr>
							<td class="label"><label for="c_desc">Description:</label></td>
							<td class="smallDesc">
								<% if (check.get("desc") != null) { %>
									<span class="error"><%=check.get("desc") %></span>
								<% } %>
								<textarea id="c_desc" class="text" cols="80" rows="7" name="desc"><%=category.getDesc() == null ? "" : category.getDesc() %></textarea>
							</td>
						</tr>
						<tr>
							<td class="label"><label for="c_parent">Parent:</label></td>
							<td class="smallDesc">
								<% if (check.get("parentId") != null) { %>
									<span class="error"><%=check.get("parentId") %></span>
								<% } %>
								<select name="parentId" <%=hasChildren==true? "disabled=\"disabled\"" : "" %> >
									<option value="0"> </option>
									<%
									for (int i = 0; i < categories.size(); i++) {
									%>
									<option value="<%=categories.get(i).getId()%>" <%=category.getParentId() == categories.get(i).getId() ? "selected=\"selected\"" : ""%>>
										|<% for (int j = 2 ; j <= categories.get(i).getLevel(); j++) {%>&nbsp;&nbsp;|<% } %>___
										<%=categories.get(i).getName()%> (<%=categories.get(i).getLevel()%>)
									</option>
									<%
									}
									%>
								</select>
							</td>
						</tr>
						<tr class="thead">
							<th colspan="2">&nbsp;</th>
						</tr>
						<tr class="thead">
							<td class="info notice" colspan="2">Define custom META tags for detail pages. Leave blank to use default tags defined for your directory.</td>
						</tr>
						<tr>
							<td class="label"><label for="c_keywords">META Keywords:</label></td>
							<td class="smallDesc">
								<% if (check.get("keywords") != null) { %>
									<span class="error"><%=check.get("keywords") %></span>
								<% } %>
								<input name="keywords" id="c_keywords" value="<%=category.getKeywords() == null ? "" : category.getKeywords() %>" class="text" maxlength="200" />
								<p class="msg notice info">Separate keywords by comma.</p>
							</td>
						</tr>
						<tr>
							<td class="label"><label for="c_metaDesc">META Description:</label></td>
							<td class="smallDesc">
								<% if (check.get("metaDesc") != null) { %>
									<span class="error"><%=check.get("metaDesc") %></span>
								<% } %>
								<textarea name="metaDesc" id="c_metaDesc" class="text"><%=category.getMetaDesc() == null ? "" : category.getMetaDesc() %></textarea> 
							</td>
						</tr>
					</tbody>
				</table>
			</div>
			<table class="formPage">
				<tbody>
					<tr>
						<td class="label"><label for="c_status">Status:</label></td>
						<td class="smallDesc">
							<% if (check.get("status") != null) { %>
								<span class="error"><%=check.get("status") %></span>
							<% } %>
							<select id="c_status" name="status">
								<option value="0" label="Inactive">Inactive</option>
								<option value="1" label="Pending">Pending</option>
								<option selected="selected" value="2" label="Active">Active</option>
							</select>
						</td>
					</tr>
				</tbody>
			</table>
			<table class="formPage">
				<tfoot>
					<tr>
						<td><input type="reset" class="button" title="Reset form" alt="Reset form" value="Reset" name="reset" id="reset-link-submit"></td>
						<td><input type="submit" class="button" title="Save link" alt="Save form" value="Save" name="save" id="send-link-submit"></td>
					</tr>
				</tfoot>
			</table>
		</form>
	</div>
<jsp:include page="/admin/layouts/footer.jsp">
    <jsp:param name="language" value="1" />
</jsp:include>